package com.zcbl.toolkit.map.baidu.http;

import com.alibaba.fastjson.JSON;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;

import java.io.IOException;

/**
 * @author he peng
 * @create 2018/4/24 12:05
 * @see
 */
public class BaiduTextJavaScriptFastJsonHttpMessageConverter extends AbstractHttpMessageConverter<Object> {

    public BaiduTextJavaScriptFastJsonHttpMessageConverter() {
        super(MediaType.valueOf("text/javascript;charset=UTF-8"));
    }

    @Override
    protected boolean supports(Class<?> clazz) {
        return true;
    }

    @Override
    protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
        return JSON.parseObject(inputMessage.getBody() , clazz);
    }

    @Override
    protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {

    }
}
